package com.freemyleft.left.zapp.net.rx;

import android.content.Context;

import com.freemyleft.left.zapp.net.RestCreator;
import com.freemyleft.left.zapp.ui.LoaderStyle;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by FreeMyleft on 2017/12/1.
 */

public class RxRestClentBuilder {
    private String mUrl = null;
    private  Map<String, Object> PARAMS = new HashMap<>() ;
    private RequestBody mRequestBody = null;
    private Context mContext = null;
    private LoaderStyle mLoaderStyle = null;
    private File mFile = null;//没有成功


    RxRestClentBuilder() {

    }


    public final RxRestClentBuilder url(String url) {
        this.mUrl = url;
        return this;
    }

    public final RxRestClentBuilder params(Map<String, Object> params) {
        PARAMS.putAll(params);
        return this;
    }

    public final RxRestClentBuilder params(String key, Object value) {

        PARAMS.put(key, value);
        return this;
    }

    public final RxRestClentBuilder file(File file) {

        this.mFile = file;
        return this;
    }

    public final RxRestClentBuilder file(String file) {

        this.mFile = new File(file);
        return this;
    }

    public final RxRestClentBuilder raw(String raw) {
        this.mRequestBody = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"), raw);
        return this;
    }

    public final RxRestClentBuilder loader(Context context, LoaderStyle style) {
        this.mContext = context;
        this.mLoaderStyle = style;
        return this;
    }

    /**
     * +
     * 默认loader
     *
     * @param context 上下文
     * @return
     */
    public final RxRestClentBuilder loader(Context context) {
        this.mContext = context;
        this.mLoaderStyle = LoaderStyle.BallSpinFadeLoaderIndicator;
        return this;
    }

    public final RxRestClient buid() {

        return new RxRestClient(mUrl, PARAMS, mRequestBody, mContext, mLoaderStyle, mFile);

    }


}
